package com.daka.entity;

import com.daka.tools.CodeMap;
import com.daka.tools.ConfigUtil;
import com.daka.tools.DateUtil;
import lombok.Data;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.type.Alias;

import java.text.ParseException;
import java.util.Date;

@SuppressWarnings("unused")
@Data
@ToString
@Alias(value = "U_VOLUNTEER")
@Slf4j
public class Volunteer {
    /**
     * .
     */
    private Long id;

    /**
     * .
     */
    private Long userId;

    /**
     * .
     */
    private String memberCode;

    /**
     * .
     */
    private String volunteerCode;

    /**
     * .
     */
    private String mobile;

    /**
     * .
     */
    private String realName;

    /**
     * .
     */
    private String nickName;

    /**
     * .
     */
    private Integer times;

    /**
     * .
     */
    private String birthDay;

    /**
     * .
     */
    private String cardno;

    /**
     * .
     */
    private String province;

    /**
     * .
     */
    private String city;

    /**
     * .
     */
    private String district;

    /**
     * .
     */
    private String residenceAddress;

    /**
     * .
     */
    private Date crateTime;

    /**
     * .
     */
    private String qq;

    /**
     * .
     */
    private String cardType;

    /**
     * .
     */
    private String education;

    /**
     * .
     */
    private String headUrl;

    /**
     * .
     */
    private String job;

    /**
     * .
     */
    private Integer locked;

    /**
     * .
     */
    private String nation;

    /**
     * .
     */
    private String nativePlace;

    /**
     * .
     */
    private Integer rank;

    /**
     * .
     */
    private String serviceField;

    /**
     * .
     */
    private String sex;

    /**
     * .
     */
    private String sign;

    /**
     * .
     */
    private String skill;

    /**
     * .
     */
    private String type;

    /**
     * .
     */
    private String weChat;

    /**
     * .
     */
    private Integer acts;

    /**
     * .
     */
    private String lastJoinActDate;

    /**
     * .
     */
    private String client;

    /**
     * .
     */
    private Integer isFinished;

    /**
     * .
     */
    private Long vTimes;

    private String tempOldId;

    public static Volunteer build(Member member, User user, Integer acts, String lastJoinActDate, Integer isFinished) {
        Volunteer volunteer = new Volunteer();
        volunteer.setUserId(user.getId());
        volunteer.setMemberCode(member.getMemberid());
        volunteer.setClient(ConfigUtil.CLIENT_ID);
        volunteer.setActs(acts);
        volunteer.setBirthDay(member.getBirthday());
        volunteer.setCardno(member.getCardno());
        volunteer.setCardType(member.getCardtype());
        volunteer.setCity(member.getCity());

        Date date;
        try {
            date = DateUtil.str2Date(member.getRegdate(), DateUtil.DATETIME_YYYY_MM_DD_HH_MM_SS);
        } catch (Exception e) {
            date = new Date();
            log.error("===============dakaqi============== Date Format Error! Volunteer UserId : " + user.getId());
        }

        volunteer.setCrateTime(date);
        volunteer.setDistrict(member.getDistrict());
        volunteer.setEducation(member.getEducation());
        volunteer.setHeadUrl(member.getHeadurl());
        volunteer.setIsFinished(isFinished);
        volunteer.setJob("其他");
        volunteer.setLastJoinActDate(lastJoinActDate);
        volunteer.setMobile(member.getBundmobile());
        volunteer.setNation(member.getNation());
        volunteer.setNativePlace(member.getNativeplace());
        volunteer.setNickName(member.getNickname());
        volunteer.setProvince(member.getProvince());
        volunteer.setQq(member.getQq());
        volunteer.setRank(0);
        volunteer.setRealName(member.getRealname());
        volunteer.setResidenceAddress(member.getResidence());
        volunteer.setServiceField(CodeMap.getUserSkillValue(member.getSkill()));
        volunteer.setSex(member.getSex());
        volunteer.setSign("");
        volunteer.setSkill("其他");
        volunteer.setTimes(member.getAlltimes() - member.getVolunteertime());
        volunteer.setType(member.getUsertype().toString());
        volunteer.setVolunteerCode(member.getVolunteercode());
        volunteer.setVTimes(member.getVolunteertime().longValue());
        volunteer.setWeChat(null);
        volunteer.setLocked(0);
        volunteer.setTempOldId(member.getId().toString());
        return volunteer;
    }
}